/*
 *  POJ1008: Maya Calendar
 */

/*-------- Includes --------*/
#include <map>
#include <iostream>

using namespace std;

/*-------- Global Variables --------*/
const char *Haab[19]    = {"pop", "no",     "zip",   "zotz",   "tzec",
                           "xul", "yoxkin", "mol",   "chen",   "yax",
                           "zac", "ceh",    "mac",   "kankin", "muan",
                           "pax", "koyab",  "cumhu", "uayet"};

const char *Tzolkin[20] = {"imix",  "ik",    "akbal", "kan",   "chicchan",
                           "cimi",  "manik", "lamat", "muluk", "ok",
                           "chuen", "eb",    "ben",   "ix",    "mem",
                           "cib",   "caban", "eznab", "canac", "ahau"};

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    map<string, int> hdict;

    for (int i = 0; i < 19; i++)
        hdict[Haab[i]] = i;

    int nOfCase;

    cin >> nOfCase;

    cout << nOfCase << endl;

    while (nOfCase--) {
        int  hday, hyear;
        int  tmon, tyear;
        int  today;
        char hmon[10];
        char temp;
        const char *tday;

        cin >> hday >> temp >> hmon >> hyear;

        today = hyear * 365 + hdict[hmon] * 20 + hday;

        tyear = today / 260; today %= 260;
        tmon  = today % 13 + 1;
        tday  = Tzolkin[today % 20];

        cout << tmon << " " << tday << " " << tyear << endl;
    }

    return 0;
}
